#ifndef _Ape__EventModel_Callback_h
#define _Ape__EventModel_Callback_h

#include <Ape/Object.h>

namespace Ape {
	namespace EventModel {
		/**
			Principles:
			1) callback MUSTN'T be called when it's neutralized
			2) callback ignores the call unless it's active
			3) callback is neutralized by the callee
			4) callback is orphaned by the caller
			5) callback is deleted by itself
			   // (it will determine that it's orphaned AND neutralized)
			6) callback is created as orphan - it stops being an orphan after the caller takes control over it
			7) callback is created as neutral - it's unneutralized by the derrivative callback after it
			8) derrivative callback stores typed callee's instance (it will call it)
			
			
		*/
		class Callback {
			TYPE_NAME ("Ape::EventModel::Callback")
		private:
			Object* m_Object;
			
			bool m_Active;
			bool m_Neutralized;
			bool m_Orphaned;
			
			void condDelete();
			
		public:
			Callback (Object* object);
			virtual ~Callback();
			
			void Activate();
			void Deactivate();
			bool isActive() const;
			
			virtual void Neutralize();
			bool isNeutralized() const;
			
			void TakeCare();
			void Leave();
			bool isOrphaned() const;
		};
	}
}

#endif // _Ape__EventModel_Callback_h
